package com.beauty.common.xml;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.List;

public class SaxTest {

	public static InputStream getXML(String path) {
		InputStream inputStream = null;
		try {
			URL url = new URL(path);
			if (url != null) {
				HttpURLConnection connection = (HttpURLConnection) url
						.openConnection();
				connection.setConnectTimeout(3 * 1000);
				connection.setDoInput(true);
				connection.setRequestMethod("GET");
				if (connection.getResponseCode() == 200) {
					inputStream = connection.getInputStream();
				}
			}
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return inputStream;
	}

	public static void main(String[] args) {
		String path = "http://localhost:9080/version.xml";
		InputStream inputStream = SaxTest.getXML(path);
		//InputStream inputStream = null;
		try {
			inputStream = new FileInputStream(new File("E:\\workspace\\beauty\\WebRoot\\version.xml"));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println(inputStream);
		List<HashMap<String, String>> list = SaxService.readXML(inputStream,
				"xBankTrans");
		System.out.println(list.size());
		for (HashMap<String, String> map : list) {
			System.out.println(map.toString());
		}
	}

}
